<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" label-width="98px" ref="queryForm" size="small" v-show="showSearch">
      <el-form-item label="框架编号" prop="projectCode">
        <el-input @keyup.enter.native="handleQuery" clearable style="width: 240px;" placeholder="请输入框架编号" size="mini"
          v-model="queryParams.projectCode" />
      </el-form-item>
      <el-form-item label="订单编号" prop="code">
        <el-input @keyup.enter.native="handleQuery" clearable placeholder="请输入订单编号" v-model="queryParams.code"
          size="mini" />
      </el-form-item>
      <el-form-item label="业务员" prop="salesmanId">
        <el-select v-model="queryParams.salesmanId" placeholder="请选择业务员" filterable clearable style="width: 100%"
          size="mini">
          <el-option v-for="item in salesmanList" :key="item.userId" :label="item.nickName" :value="item.userId" />
        </el-select>
      </el-form-item>
      <el-form-item label="买方名称" prop="customName">
        <el-input @keyup.enter.native="handleQuery" clearable placeholder="请输入买方名称" size="mini"
          v-model="queryParams.customName" />
      </el-form-item>

      <el-form-item label="制单人" prop="createName">
        <el-input @keyup.enter.native="handleQuery" clearable placeholder="请输入制单人" size="mini"
          v-model="queryParams.createName" />
      </el-form-item>
      <!-- <el-form-item label="下单日期" prop="orderDate">
        <el-date-picker clearable v-model="queryParams.orderDate" type="date" value-format="yyyy-MM-dd" size="mini"
          placeholder="请选择下单日期">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="下单日期">
        <el-date-picker v-model="dateRange" style="display: flex;" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="项目状态" prop="status">
        <el-select clearable placeholder="请选择项目状态" style="width: 200px" v-model="queryParams.status" size="mini">
          <el-option :key="dict.value" :label="dict.label" :value="dict.value" v-for="dict in dict.type.pro_status" />
        </el-select>
      </el-form-item>

      <el-form-item label="订单类别" prop="goodsType">
        <el-select clearable placeholder="选择订单类别" style="width: 200px" v-model="queryParams.goodsType" size="mini">
          <el-option :key="dict.value" :label="dict.label" :value="dict.value"
            v-for="dict in dict.type.order_goods_type" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>
        <el-button @click="handleAdd" icon="el-icon-plus" plain size="mini" type="primary"
          v-hasPermi="['develop:ProjectBaseInfo:add']">新增订单
        </el-button>
        <el-button @click="handleAddIron" icon="el-icon-plus" plain size="mini" type="primary"
          v-hasPermi="['develop:ProjectBaseInfo:add']">新增铁件订单
        </el-button>
        <el-button type="info" icon="el-icon-upload2" size="mini"
          @click="showUploadDialogOrderAndGoods">导入订单产品</el-button>
        <el-button type="success" icon="el-icon-upload2" size="mini" @click="showUploadDialogIron">导入铁件订单</el-button>
        <el-button type="success" icon="el-icon-upload2" size="mini"
          @click="showUploadDialogGoodsOrder">导入订单（不含产品）</el-button>
        <el-button type="success" icon="el-icon-upload2" size="mini"
          @click="showUploadDialogIronContainDetail">导入铁件明细</el-button>
        <el-popconfirm title="确认提交选择的数据项？" @confirm="handleBatchSubmit({})">
          <el-button slot="reference" type="success" plain icon="el-icon-finished" size="mini" :disabled="multiple"
            style="margin-left:10px;">批量审核到库管
          </el-button>
        </el-popconfirm>
        <el-button type="warning" plain icon="el-icon-document" :disabled="multiple" size="mini"
          style="margin-left:10px;" @click="handleGoodsMerge()">产品合计
        </el-button>

        <el-button type="warning" plain icon="el-icon-document" :disabled="multiple" size="mini"
          style="margin-left:10px;" @click="handleGoodsNoMerge()">不合并产品的合计
        </el-button>

        <el-popconfirm :title="`确认删除数据项？`" @confirm="handleDelete({})" style="margin-left: 10px;">
          <el-button slot="reference" type="danger" plain icon="el-icon-delete" :disabled="multiple" size="mini"
            style="">批量删除
          </el-button>
        </el-popconfirm>
        <el-button style="margin-left: 10px;" type="info" icon="el-icon-upload2" size="mini" @click="uploadHetongSale"
          v-hasPermi="['develop:GoodsSaleChuan:export']">导入合同产品</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="dataList" @sort-change="handleSortChange" :max-height="tableMaxHeight" show-summary
      :summary-method="getSummaries" border style="width: 100%" @selection-change="handleSelectionChange"
      v-loading="loading">
      <el-table-column align="center" type="selection" width="55" />
      <el-table-column align="center" label="框架编号" prop="projectCode" />
      <el-table-column sortable align="center" label="订单编号" prop="code">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="handleUpdateDetail(scope.row)" style="color: #00afff;cursor:pointer;">
              {{ scope.row.code }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="合同交货期" prop="deliveryTime" />
      <el-table-column sortable align="center" label="下单时间" prop="orderDate" />
      <el-table-column sortable align="center" label="买方" prop="customName" />
      <el-table-column sortable align="center" label="业务员" prop="salesmanName" />
      <el-table-column sortable align="center" label="制单人" prop="createName" />
      <el-table-column sortable align="center" label="项目状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pro_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="地区" prop="area">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_area" :value="scope.row.area" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="来源" prop="source">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_source" :value="scope.row.source" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="订单类型" prop="goodsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_goods_type" :value="scope.row.goodsType" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="订单金额" prop="contractMoney" />
      <el-table-column label="备注信息" align="center" prop="information" show-overflow-tooltip />
      <el-table-column align="center" label="附件" prop="attachment" show-overflow-tooltip>
        <template slot-scope="scope">
          <file-upload-show :value="scope.row.attachment"></file-upload-show>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="200" fixed="right">
        <template slot-scope="scope">

          <el-button @click="ChoseGoodsNew(scope.row)" v-if="scope.row.status === '0'" icon="el-icon-plus" size="mini"
            type="text">
            产品选择
          </el-button>
          <el-popover placement="top" width="200">
            <div style="text-align: right; margin: 0">
              <!--<el-button @click="fenpeiNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            分配任务
          </el-button>
          <el-button @click="GongxuGoodsNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            工序选择
          </el-button>-->
              <el-button @click="productShow(scope.row)" icon="el-icon-view" size="mini" type="text">
                合同产品
              </el-button>
              <el-button @click="shedinggongxu(scope.row)" icon="el-icon-view" size="mini" type="text">
                订单产品
              </el-button>
              <el-button @click="fahuoDeatil(scope.row)" icon="el-icon-view" size="mini" type="text">
                发货记录
              </el-button>
              <!--<el-button @click="wuliaoProject(scope.row)" icon="el-icon-plus" size="mini" type="text">
            用料明细
          </el-button>-->
              <el-button @click="disassemble(scope.row)" icon="el-icon-folder-add" size="mini" type="text"
                v-if="scope.row.goodsType === '1'">
                铁件拆解
              </el-button>
              <el-button v-if="scope.row.commissionStatus === '0'" @click="calculateCommission(scope.row)"
                icon="el-icon-money" size="mini" type="text">
                计算提成
              </el-button>
              <el-button v-if="scope.row.commissionStatus === '1'" @click="commissionDetail(scope.row)"
                icon="el-icon-money" size="mini" type="text">
                提成详情
              </el-button>
              <el-button
                v-if="scope.row.goodsType === '0' || scope.row.goodsType === '2' || scope.row.goodsType === '3'"
                size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['develop:ProjectBaseInfo:edit']">修改订单
              </el-button>
              <el-button v-if="scope.row.goodsType === '1'" size="mini" type="text" icon="el-icon-edit"
                @click="handleUpdateIron(scope.row)" v-hasPermi="['develop:ProjectBaseInfo:edit']">修改订单
              </el-button>
              <el-popconfirm :title="`确认删除 ` + scope.row.code + ` 数据项？`" @confirm="handleDelete(scope.row)"
                v-if="scope.row.status === '0'" style="margin-left: 10px;">
                <el-button icon="el-icon-delete" size="mini" slot="reference" type="text">删除
                </el-button>
              </el-popconfirm>
            </div>
            <el-button slot="reference" size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>

    <pagination :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total" @pagination="getList"
      v-show="total > 0" />
    <upload-dialog ref="uploadDialog" @ok="getList" @handleFileSuccess="handleFileSuccess"></upload-dialog>
    <upload-dialog ref="uploadDialogOrderAndGoods" @ok="getList"
      @handleFileSuccess="handleFileSuccessOrderAndGoods"></upload-dialog>
    <upload-dialog ref="uploadDialogOrderIron" @ok="getList" @handleFileSuccess="handleFileSuccessIron"></upload-dialog>
    <upload-dialog ref="uploadDialogOrderNoGoods" @ok="getList"
      @handleFileSuccess="handleFileSuccessOrderNoGoods"></upload-dialog>

    <upload-dialog-for-iron-goods ref="uploadDialogOrderIronDetail" @handleFileSuccess="handleFileSuccessIronDetail"
      @ok="getList"></upload-dialog-for-iron-goods>
    <projectBaseInfo-form @ok="getList" ref="form"></projectBaseInfo-form>
    <projectBaseInfo-iron-form @ok="getList" ref="ironForm"></projectBaseInfo-iron-form>
    <project-base-info-form-for-prj @ok="getList" ref="ProjectBaseInfoFormForPrj"></project-base-info-form-for-prj>
    <order-iron-record-list-module ref="orderIronRecord"></order-iron-record-list-module>
    <goodsChoseForm-list ref="goodsChoseForm"></goodsChoseForm-list>
    <allGoodsForm-List ref="allGoodsForm"></allGoodsForm-List>
    <process-list ref="processlist"></Process-list>
    <allocating-task ref="allocatingtask"></allocating-task>
    <order-commission-record-form ref="commissionForm" @ok="getList"></order-commission-record-form>
    <order-commission-record-detail ref="commissionDetail" @ok="getList"></order-commission-record-detail>
    <yongliaoMingxi-form-list-porject ref="wuliaoProjectForm" @ok="getList"></yongliaoMingxi-form-list-porject>
    <fahuoDeatil-form-list ref="fahuoDeatilForm" @ok="getList"></fahuoDeatil-form-list>

    <goods-order-merge-list ref="goodsOrderMergeList"></goods-order-merge-list>
    <goods-order-no-merge-list ref="goodsOrderNoMergeList"></goods-order-no-merge-list>
    <contractual-product ref="contractualProduct"></contractual-product>
    <upload-dialog ref="uploadHetongSale" @ok="getList"
      @handleFileSuccess="handleFileSuccessHetongSale"></upload-dialog>
  </div>
</template>

<script>
import { accAdd, deleteAction, downloadFile, getAction } from '@/api/manage'
import ContractualProduct from "./module/ContractualProduct";

//form表单
import ProjectBaseInfoForm from './module/ProjectBaseInfoForm'
import ProjectBaseInfoFormForPrj from "./module/ProjectBaseInfoFormForPrj";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { treeselect } from "@/api/system/dept";
import UploadDialog from "@/views/upload/UploadDialog";
import GoodsChoseFormList from "./prjForGoodsIn/GoodsChoseFormList";
import ProcessList from "@/views/develop/process/ProcessList";
import AllocatingTask from "@/views/develop/process/AllocatingTask";
import OrderIronRecordListModule from "@/views/develop/orderIronRecord/module/OrderIronRecordListModule";
import AllGoodsFormList from "./prjForGoodsIn/AllGoodsFormList";
import OrderCommissionRecordForm from "@/views/develop/orderCommissionRecord/module/OrderCommissionRecordForm.vue";
import OrderCommissionRecordDetail from "@/views/develop/orderCommissionRecord/module/OrderCommissionRecordDetail.vue";
import YongliaoMingxiFormListPorject from '@/views/develop/goodsSaleMaterial/module/YongliaoMingxiFormListPorject'
import FahuoDeatilFormList from '@/views/develop/lvYifahuomingxi/module/FahuoDeatilFormList'
import GoodsOrderMergeList from "@/views/develop/projectBaseInfo/prjForGoodsIn/GoodsOrderMergeList.vue";
import GoodsOrderNoMergeList from "@/views/develop/projectBaseInfo/prjForGoodsIn/GoodsOrderNoMergeList.vue";
import ProjectBaseInfoIronForm from "@/views/develop/projectBaseInfo/module/ProjectBaseInfoIronForm.vue";
import FileUploadShow from "@/components/FileUpload/FileUploadShow.vue";
import UploadDialogForIronGoods from "@/views/upload/UploadDialogForIronGoods.vue";
//import FpTaskFormList from "./prjForGoodsIn/FpTaskFormList";

export default {
  name: "ProjectBaseInfoList",
  dicts: ['yes_no', 'fund_callback', 'fund_status', 'tax_status', 'pro_status', 'order_area', 'order_goods_type', "project_source"],
  components: {
    UploadDialogForIronGoods,
    FileUploadShow,
    ProjectBaseInfoIronForm,
    GoodsOrderMergeList,
    GoodsOrderNoMergeList,
    OrderCommissionRecordDetail,
    OrderCommissionRecordForm,
    OrderIronRecordListModule,
    ProjectBaseInfoForm,
    ProjectBaseInfoFormForPrj,
    Treeselect,
    UploadDialog,
    GoodsChoseFormList,
    ProcessList,
    AllocatingTask,
    AllGoodsFormList,
    YongliaoMingxiFormListPorject,
    FahuoDeatilFormList,
    ContractualProduct
    //FpTaskFormList,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单基础信息管理表格数据
      dataList: [],
      dateRange: [],
      salesmanList: [],
      // 查询参数
      queryParams: {
        yearStr: null,
        pageNum: 1,
        pageSize: 20,
        name: null,
        status: null,
        code: null,
        master: null,
        customId: null,
        orderDate: null,
        projectCode: null,
        salesmanId: null,
        customName: null,
        companyName: null,
        contractDate: null,
        contractMoney: null,
        auditMoney: null,
        checkDate: null,
        checkState: null,
        fundCallback: null,
        createName: null,
        information: null,
        source: null,
        goodsType: null,
        orderByColumn: "create_time",
        isAsc: "desc",
        params: {},
      },
      url: {
        list: '/projectBaseInfo/projectBaseInfo/list',
        remove: '/projectBaseInfo/projectBaseInfo/',
        export: '/projectBaseInfo/projectBaseInfo/export',
        submitProject: '/projectBaseInfo/projectBaseInfo/submitProject',
        salesmanList: '/system/role/authUser/allocatedList',
        submit: '/projectBaseInfo/projectBaseInfo/submit/',
      },
      tableMaxHeight: window.innerHeight - 320,
      // 部门树选项
      deptOptions: [],
      baseUrl: process.env.VUE_APP_BASE_API,
    };
  },
  created() {
    this.initQuery();
    this.getList();
    this.getTreeselect();
    this.getSalesmanList();
  },
  methods: {
    uploadHetongSale() {
      this.$refs.uploadHetongSale.title = "合同产品信息导入";
      this.$refs.uploadHetongSale.tmplName = "合同产品模板.xlsx";
      this.$refs.uploadHetongSale.fileName = "合同产品信息.xlsx";
      this.$refs.uploadHetongSale.uploadUrl = "/projectBaseInfo/projectBaseInfo/imporGoodsChuan";
      this.$refs.uploadHetongSale.show();
    },
    handleFileSuccessHetongSale(response, file, fileList) {
      this.$refs.uploadHetongSale.open = false;
      this.$refs.uploadHetongSale.isUploading = false;
      /* if (response.data.code == "200") {
         this.$alert(
           "导入订单数据：" + response.data.orderInsertCount + "条！" + "</br>"+
           "导入订单数据：" + response.data.orderUpdateCount + "条！" + "</br>"+
           response.data.errorText, "导入结果", {dangerouslyUseHTMLString: true});
       } else {
         this.$alert("导入订单数据：" + response.data.orderInsertCount + "条！"+
           "导入订单数据：" + response.data.orderUpdateCount + "条！" + "</br>"+
           response.data.errorText, "导入结果", {dangerouslyUseHTMLString: true});
       }*/
      if (response.data.code == "200") {
        this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      } else {
        this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },

    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.handleQuery();
    },
    fahuoDeatil(row) {
      this.$refs.fahuoDeatilForm.show(row);
    },
    wuliaoProject(row) {
      this.$refs.wuliaoProjectForm.show(row);
    },
    getSalesmanList() {
      getAction(this.url.salesmanList, { "roleId": "e1c2bca31b7944e98f79008c726cf7e8" }).then(response => {
        this.salesmanList = response.rows;
      });
    },
    fpTask(row) {
      this.$refs.fpTaskForm.fpTaskShow(row);
    },
    shedinggongxu(row) {
      this.$refs.allGoodsForm.shedingGygx(row);
    },
    productShow(row) {
      this.$refs.contractualProduct.productOpen(row);
    },
    lookGoods(row) {
      this.$refs.lookGoodsForm.handleUpdate(row);
    },
    initQuery() {
      let that = this;
      if (that.$route.query.dataFlag) {
        that.queryParams.params.dataFlag = that.$route.query.dataFlag;
      }
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    submitProject(row) {
      getAction(this.url.submitProject, { id: row.id, status: "2" }).then(response => {
        this.getList();
        this.$modal.msgSuccess("提交成功!");
      }).catch(() => {
      });
    },
    exportExcel(id) {
      let that = this;
      that.loading = false;
      that.$confirm('是否确认导出详细信息信息?', "确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        downloadFile('/projectBaseInfo/projectBaseInfo/exportExcel', id);
      });
    },
    fapiaoHX(row, type) {
      let that = this;
      that.$refs.InvoiceInfoListDialog.showAllInvoices(row);
    },
    handleAddFeeInfo(row) {
      let that = this;
      // that.$refs.ProjectFeeInfoFormForPrj.handleAddNew(row);
      that.$refs.ProjectBaseInfoFormGoodsFee.handleUpdate(row);
    },
    handleUpdateDetail(row) {
      this.$refs.ProjectBaseInfoFormForPrj.handleUpdateDetail(row);
    },
    /** 查询项目基础信息管理列表 */
    getList() {
      this.loading = true;
      this.addDateRange(this.queryParams, this.dateRange, "OrderDate");
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd();
    },

    /** 新增按钮操作 */
    handleAddIron() {
      this.$refs.ironForm.handleAdd();
    },

    // 分配任务
    fenpeiNew(row) {
      this.$refs.allocatingtask.handleUpdate(row);
    },
    // 工序选择
    GongxuGoodsNew(row) {
      this.$refs.processlist.handleUpdate(row);
    },
    ChoseGoodsNew(row) {
      this.$refs.goodsChoseForm.handleUpdate(row);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    handleUpdateIron(row) {
      this.$refs.ironForm.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let list = this.dataList;
      for (const id of ids) {
        for (let i = 0; i < list.length; i++) {
          if (list[i].id === id) {
            if (list[i].status !== '0') {
              this.$modal.msgError("请选择创建中状态的订单！");
              return;
            }
          }

        }
      }


      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },


    handleFileSuccess(response, file, fileList) {
      this.$refs.uploadDialog.open = false;
      this.$refs.uploadDialog.isUploading = false;
      if (response.data.code == "200") {
        this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      } else {
        this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },
    showUploadDialog() {
      this.$refs.uploadDialog.title = "信息导入";
      this.$refs.uploadDialog.tmplName = "订单信息模板.xlsx";
      this.$refs.uploadDialog.fileName = "订单信息.xlsx";
      this.$refs.uploadDialog.uploadUrl = "/projectBaseInfo/projectBaseInfo/importData";
      this.$refs.uploadDialog.show();
    },
    /** 导出按钮操作 */
    handleExport() {
      let that = this;
      that.loading = false;
      that.$confirm('是否确认导出项目信息表?', "确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        downloadFile('/projectBaseInfo/projectBaseInfo/exportBaseInfo', that.queryParams);
      });
    },

    showUploadDialogOrderAndGoods() {
      this.$refs.uploadDialogOrderAndGoods.title = "订单产品信息导入";
      this.$refs.uploadDialogOrderAndGoods.tmplName = "订单产品模板.xlsx";
      this.$refs.uploadDialogOrderAndGoods.fileName = "订单产品信息.xlsx";
      this.$refs.uploadDialogOrderAndGoods.uploadUrl = "/projectBaseInfo/projectBaseInfo/importOrderAndGoodsData";
      this.$refs.uploadDialogOrderAndGoods.show();
    },

    // 导入铁件订单
    showUploadDialogIron() {
      this.$refs.uploadDialogOrderIron.title = "铁构件订单信息导入";
      this.$refs.uploadDialogOrderIron.tmplName = "铁构件订单模板.xlsx";
      this.$refs.uploadDialogOrderIron.fileName = "铁构件订单模板.xlsx";
      this.$refs.uploadDialogOrderIron.uploadUrl = "/projectBaseInfo/projectBaseInfo/importOrderForIron";
      this.$refs.uploadDialogOrderIron.show();
    },


    // 导入金具订单（不含产品）
    showUploadDialogGoodsOrder() {
      this.$refs.uploadDialogOrderNoGoods.title = "订单（不含产品）信息导入";
      this.$refs.uploadDialogOrderNoGoods.tmplName = "订单（不含产品）模板.xlsx";
      this.$refs.uploadDialogOrderNoGoods.fileName = "订单（不含产品）模板.xlsx";
      this.$refs.uploadDialogOrderNoGoods.uploadUrl = "/projectBaseInfo/projectBaseInfo/importOrderNoGoods";
      this.$refs.uploadDialogOrderNoGoods.show();
    },


    // 导入铁件订单（带明细）
    showUploadDialogIronContainDetail() {
      this.$refs.uploadDialogOrderIronDetail.title = "铁构件订单（带明细）信息导入";
      this.$refs.uploadDialogOrderIronDetail.tmplName = "铁构件订单模板（明细）.xlsx";
      this.$refs.uploadDialogOrderIronDetail.fileName = "铁构件订单模板（明细）.xlsx";
      this.$refs.uploadDialogOrderIronDetail.uploadUrl = "/projectBaseInfo/projectBaseInfo/importOrderForIronDetail";
      this.$refs.uploadDialogOrderIronDetail.show();
    },

    handleFileSuccessIronDetail(response, file, fileList) {
      this.$refs.uploadDialog.open = false;
      this.$refs.uploadDialog.isUploading = false;
      if (response.data.code == "200") {
        this.$alert(
          "导入订单数据：" + response.data.orderInsertCount + "条！" + "</br>" +
          "导入产品数据：" + response.data.ironDetailInsertCount + "条！" + "</br>" +
          response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      } else {
        this.$alert("导入订单数据：" + response.data.orderInsertCount + "条！" +
          "导入订单数据：" + response.data.orderUpdateCount + "条！" + "</br>" +
          response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },



    handleFileSuccessOrderAndGoods(response, file, fileList) {
      this.$refs.uploadDialog.open = false;
      this.$refs.uploadDialog.isUploading = false;
      if (response.data.code == "200") {
        this.$alert("导入订单数据：" + response.data.orderInsertCount + "条！" + "</br>"
          + "导入商品数据：" + response.data.goodsInsertCount + "条！更新商品数据：" + response.data.goodsUpdateCount + "条！" + "</br>"
          + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      } else {
        this.$alert("导入数据：" + response.data.orderInsertCount + "条！"
          + "导入商品数据：" + response.data.goodsInsertCount + "条！更新商品数据：" + response.data.goodsUpdateCount + "条！"
          + response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },
    handleFileSuccessIron(response, file, fileList) {
      this.$refs.uploadDialog.open = false;
      this.$refs.uploadDialog.isUploading = false;
      if (response.data.code == "200") {
        this.$alert(
          "导入订单数据：" + response.data.orderInsertCount + "条！" + "</br>" +
          "导入订单数据：" + response.data.orderUpdateCount + "条！" + "</br>" +
          response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      } else {
        this.$alert("导入订单数据：" + response.data.orderInsertCount + "条！" +
          "更新订单数据：" + response.data.orderUpdateCount + "条！" + "</br>" +
          response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },

    handleFileSuccessOrderNoGoods(response, file, fileList) {
      this.$refs.uploadDialogOrderNoGoods.open = false;
      this.$refs.uploadDialogOrderNoGoods.isUploading = false;
      if (response.data.code == "200") {
        this.$alert(
          "导入订单数据：" + response.data.orderInsertCount + "条！" + "</br>" +
          "更新订单数据：" + response.data.orderUpdateCount + "条！" + "</br>" +
          response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      } else {
        this.$alert("导入订单数据：" + response.data.orderInsertCount + "条！" +
          "导入订单数据：" + response.data.orderUpdateCount + "条！" + "</br>" +
          response.data.errorText, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },


    disassemble(row) {
      this.$refs.orderIronRecord.show(row.id);
    },

    calculateCommission(row) {
      this.$refs.commissionForm.handleAdd(row);
    },

    commissionDetail(row) {
      this.$refs.commissionDetail.handleShowByOrderId(row);
    },

    handleBatchSubmit(row) {
      const ids = row.id || this.ids;
      getAction(this.url.submit + ids, {}).then(response => {
        this.getList();
        this.$modal.msgSuccess("批量提交成功");
      }).catch(() => {
      });
    },

    handleGoodsMerge() {
      const ids = this.ids;
      this.$refs.goodsOrderMergeList.show(ids);
    },

    handleGoodsNoMerge() {
      const ids = this.ids;
      this.$refs.goodsOrderNoMergeList.show(ids);
    },

    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        // 只合计amount1和amount3，想合并哪些列就在这里指定
        if (column.property === "contractMoney" || column.property === "taxAll" || column.property === "taxRemain"
          || column.property === "backMoney" || column.property === "remainMoney") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return accAdd(prev, curr);
            } else {
              return prev;
            }
          }, 0);
        }
      });
      return sums;
    },


  }
};
</script>
